package com.bootdo.system.dao;

import com.bootdo.system.domain.RedBagConfig;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface RedBagConfigMapper {

	@Select("select * from tb_RedBag_config where id = #{id}")
	RedBagConfig get(Long id);
	
	@Select("select * from tb_RedBag_config limit 1")
	RedBagConfig getConfig();
	
	@Select("select * from tb_RedBag_config")
	List<RedBagConfig> list(Map<String,Object> map);
	
	@Insert("insert into tb_RedBag_config (`newPoint`, `newCount`, `shareCount`, `shareStart`, `shareEnd`,`maxPercent`, `createUserId`, `createTime`,`shareMaxPercent`)"
	+ "values (#{newPoint}, #{newCount}, #{shareCount},  #{shareStart}, #{shareEnd}, #{maxPercent},#{createUserId}, now(),#{shareMaxPercent})")
	@Options(useGeneratedKeys=true)
	int save(RedBagConfig bComments);
	
	@Update("<script>"+ 
			"update tb_RedBag_config " + 
					"<set>" + 
		            "<if test=\"id != null\">`id` = #{id}, </if>" + 
                    "<if test=\"newPoint != null\">`newPoint` = #{newPoint}, </if>" + 
                    "<if test=\"newCount != null\">`newCount` = #{newCount}, </if>" + 
                    "<if test=\"shareStart != null\">`shareStart` = #{shareStart}, </if>" + 
                    "<if test=\"shareEnd != null\">`shareEnd` = #{shareEnd}, </if>" + 
                    "<if test=\"shareCount != null\">`shareCount` = #{shareCount}, </if>" +    
                    "<if test=\"maxPercent != null\">`maxPercent` = #{maxPercent}, </if>" +   
                    "<if test=\"shareMaxPercent != null\">`shareMaxPercent` = #{shareMaxPercent}, </if>" +   
                    "`updateTime` = now()," +   
          			"</set>" + 
					"where id = #{id}"+
			"</script>")
	int update(RedBagConfig bComments);
	
	@Delete("delete from tb_RedBag_config where id =#{id}")
	int remove(Long id);
	
}
